package com.example.listsort;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class MainTest {

    public static void main(String[] args) {
        test1();
    }

    public static void test1() {

        // list1
        List<Integer> list1 = new ArrayList<>();
        SecureRandom rand = new SecureRandom();
        for (int i = 0; i < 10000; i++) {
            list1.add(rand.nextInt(1000));
        }
        // list2
        List<Integer> list2 = new ArrayList<>(list1);

        // // list.sort() 方法对list1 排序
        // long startTime = System.currentTimeMillis();
        // list1.sort(Comparator.comparing(Integer::intValue));
        // System.out.println("List.sort()耗时：" + (System.currentTimeMillis() - startTime) + "ms");
        //
        // // stream().sorted() 对list2 排序
        // long startTime1 = System.currentTimeMillis();
        // list2.stream().sorted(Comparator.comparing(Integer::intValue)).collect(Collectors.toList());
        // System.out.println("stream.sort耗时：" + (System.currentTimeMillis() - startTime1) + "ms");


        // stream().sorted() 对list2 排序
        long startTime1 = System.currentTimeMillis();
        list2.stream().sorted(Comparator.comparing(Integer::intValue)).collect(Collectors.toList());
        System.out.println("stream.sort耗时：" + (System.currentTimeMillis() - startTime1) + "ms");

        // list.sort() 方法对list1 排序
        long startTime = System.currentTimeMillis();
        list1.sort(Comparator.comparing(Integer::intValue));
        System.out.println("List.sort()耗时：" + (System.currentTimeMillis() - startTime) + "ms");


    }
}
